package com.company.bs2023;

/**
 * TODO
 *
 * @author jianf
 * @date 2023年04月16 10:57
 */
public class EatingGrape {
    public static void main(String[] args) {
        EatingGrape solution = new EatingGrape();
        //int[] s = {3，6，7,11};
        //int result = solution.calcMinSpeed(4，8，s);

        //1- 16,8
        //15,12,10,21,22,20,7,6,20,14,23,19,12,6,24,8
       /* int[] s = {15, 12, 10, 21, 22, 20, 7, 6, 20, 14, 23, 19, 12, 6, 24, 8};
        int result = solution.calcMinSpeed(16, 8, s);*/

        //2-  9,13
        //14,11,35,21,30,25,5,15,68
        int[] s = {23, 4, 24, 11, 12, 41, 33, 24, 4, 38, 12, 45, 20};
        long start = System.currentTimeMillis();
        int result = solution.calcMinSpeed(13, 15, s);
        long end = System.currentTimeMillis();
        System.out.println(start);
        System.out.println(end);
        System.out.println(result);

//        LocalTime lt = LocalTime.of(23, 34, 20, 400000);
//        System.out.println(lt.toString());
//        System.out.println(lt.format(DateTimeFormatter.ISO_LOCAL_TIME));
//        System.nanoTime();
    }

    public int calcMinSpeed(int n, int h, int[] s) {
        int k = 0, reh = h;
        while (h <= reh) {
            k++;
            reh = 0;
            for (int i = 0; i < n; i++) {
                reh += (s[i] / k + (s[i] % k > 0 ? 1 : 0));
            }
            if (h == reh) {
                break;
            }
        }
        return k;
    }
}

